<html>
<head><meta charset="utf-8"><title>should valid fn be callable ? · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html">should valid fn be callable ?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="154256225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154256225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154256225">(Jan 03 2019 at 18:23)</a>:</h4>
<blockquote>
<p>what is the gain from this requirement? </p>
</blockquote>
<p>AFAICT that allows us to make the function pointer <code>dereferenceable</code>.</p>



<a name="154256535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154256535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154256535">(Jan 03 2019 at 18:27)</a>:</h4>
<p>i don't know if that impacts any optimizations</p>



<a name="154256963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154256963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154256963">(Jan 03 2019 at 18:32)</a>:</h4>
<p>right</p>



<a name="154256973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154256973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154256973">(Jan 03 2019 at 18:33)</a>:</h4>
<p>presuming that's even a valid LLVM attribute to apply to such a type</p>



<a name="154257619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154257619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154257619">(Jan 03 2019 at 18:41)</a>:</h4>
<p>right ! So <code>dereferenceable(n)</code> tells LLVM that <code>n</code> bytes are dereferenceable through the pointer, does that make sense for function pointers ? they don't "load" or "write" to bytes, but jump to the address instead.</p>



<a name="154257690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154257690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154257690">(Jan 03 2019 at 18:42)</a>:</h4>
<p>right, this is what <span class="user-mention" data-user-id="120791">@RalfJ</span> was saying -- it's not like we're going to insert "extra" calls to functions</p>



<a name="154257697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154257697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154257697">(Jan 03 2019 at 18:42)</a>:</h4>
<p>the requirement that the <code>fn()</code> pointer must be <code>nonnull</code> is already enough for that AFAICT, so this might not buy us anything</p>



<a name="154257715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154257715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154257715">(Jan 03 2019 at 18:42)</a>:</h4>
<p>ah, I didn't understood that part before</p>



<a name="154257741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154257741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154257741">(Jan 03 2019 at 18:43)</a>:</h4>
<p>(in contrast to pointers, where there may be value in doing a load earlier even if it wouldn't have happened before)</p>



<a name="154257754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154257754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154257754">(Jan 03 2019 at 18:43)</a>:</h4>
<p>e.g. to pull it out of a loop or something</p>



<a name="154262602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154262602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ariel Ben-Yehuda <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154262602">(Jan 03 2019 at 19:59)</a>:</h4>
<p>I don't want to get into what it means for an fn being "callable"</p>



<a name="154401618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should%20valid%20fn%20be%20callable%20%3F/near/154401618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/should.20valid.20fn.20be.20callable.20.3F.html#154401618">(Jan 04 2019 at 10:45)</a>:</h4>
<blockquote>
<p>the requirement that the <code>fn()</code> pointer must be <code>nonnull</code> is already enough for that AFAICT, so this might not buy us anything</p>
</blockquote>
<p>exactly</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>